package cn.tj212.xiaoyin.core.statics.service.impl;

import cn.tj212.xiaoyin.core.statics.dao.CourseStudyStaticsDao;
import cn.tj212.xiaoyin.core.statics.domain.CourseStudyStaticsDto;
import cn.tj212.xiaoyin.core.statics.domain.StaticsVO;
import cn.tj212.xiaoyin.core.statics.service.IStaticsService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class StaticsServiceImpl implements IStaticsService {

    @Autowired
    private CourseStudyStaticsDao entityDao;

    @Override
    public StaticsVO queryCourseStudyStatistics(CourseStudyStaticsDto queryEntity) {
        List<CourseStudyStaticsDto> list=entityDao.queryCourseStudyStatistics(queryEntity);
        StaticsVO resultVo=new StaticsVO();
        List<String> categories=new ArrayList<String>();
        List<Integer> data=new ArrayList<Integer>();

        if (CollectionUtils.isNotEmpty(list)){
            for (CourseStudyStaticsDto item:list
                 ) {
                categories.add(item.getDateStr());
                data.add(item.getTotalCount());
            }
            resultVo.setCategories(categories);
            resultVo.setData(data);
        }
        return resultVo;
    }
}
